# Maintainer: David Runge <dvzrv@archlinux.org>

_name=MediathekView
pkgname=mediathekview
pkgver=13.9.1
pkgrel=1
pkgdesc="Access the Mediathek of many German TV stations"
arch=(any)
url="https://github.com/mediathekview/mediathekview"
license=(GPL3)
depends=(bash hicolor-icon-theme java-runtime)
makedepends=(maven strip-nondeterminism)
conflicts=(mediathek)
provides=(mediathek)
replaces=(mediathek)
optdepends=(
  'libnotify: to use desktop notifications'
  'mplayer: for recording streams'
  'vlc: for stream playback'
)
source=(
  $pkgname-$pkgver.tar.gz::https://github.com/$pkgname/$pkgname/archive/refs/tags/$pkgver.tar.gz
  de.$pkgname.$_name.desktop
  $pkgname.sh
)
sha512sums=('f706a2fdf458b6dccec34b35df6b5fa831eba851ca694150f48f396b87a957315d3380648e59e2e9c76475010d6fdcda72cb8e7e42cceee2bc3b2524235bb7e6'
            '24a94a078180aca7c50ed7763ef4806c116c27f901f644ef570ee413ffc3ac795b5ebd24d696a9b2ec426e7c9b6eaf8a8b22addb5ac7c9fe9700f7c04305f64b'
            '24313f9873aef8680eb466d756c0f537c4d2320e51296f354422bcf70f8f42ffff481c7db0cf58024b2953efb1f7442728e3e977c1ad03aaf3b9c47a535cc6a0')
b2sums=('4b9826d1fbeceded9248e4938ae49c964637143b4bdb635f1f1b91388312a9506732ace34e92677edeaf635fd6b937a92259a692136e8ddf822e8b05c57abe10'
        '6dbcdea2918009621fc132b4ff1056ef79f06e27c3299b69ccd7e3cb2b093e3a2a5f76acd6b1ab62689edd867ac1650f61bf829f2a1c575835d31e117d9b9ae5'
        'cbf668c6ccfb42b575d40de256ec03bb7863ea7db0bb02586f6727728fb5f1f004169849bfa9082a40b93042dc9c8f330c743e5983847c0a20f5d613748bae60')

build() {
  cd $_name-$pkgver
  ./mvnw clean install -Plinux,install4j-linux
  # Timestamps in JAR files generated by Maven do not honour SOURCE_DATE_EPOCH
  # (https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318)
  find . -type f -iname "*.jar" -exec strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" {} \;
}

package() {
  local _size

  cd $_name-$pkgver
  # jar
  install -vDm 644 target/$_name.jar -t "$pkgdir/usr/share/java/$pkgname/"
  # script
  install -vDm 755 ../$pkgname.sh "$pkgdir/usr/bin/$pkgname"
  # XDG desktop file
  install -vDm 644 ../de.mediathekview.$_name.desktop -t "$pkgdir/usr/share/applications/"
  # icons
  for _size in 16 32 48 128; do
    install -vDm 644 target/${_name}@x$_size.png "$pkgdir/usr/share/icons/hicolor/${_size}x$_size/apps/$pkgname.png"
  done
  install -vDm 644 res/$_name.svg -t "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  # docs
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
